Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: initial implementation of showing clustered responses #119

Open
wants to merge 12 commits into
base: main
Choose a base branch
from

Conversation

wpf500
Copy link
Member

@wpf500 wpf500 commented Jan 6, 2025

This PR adds the ability to see clusters of responses on the Atlas. Previously if multiple responses were too close together you could only see one of them.

This feature respects the Atlas max zoom setting which allows admins to control the maximum "declustering" zoom point. Previously it was hard coded that all clusters disappeared at a certain zoom level because you could only see responses on their own, not in a cluster.

grafik

@wpf500 wpf500 force-pushed the feat/1247-overlapping-responses branch from 3f48dad to 5c5f7f3 Compare January 7, 2025 16:26
@wpf500 wpf500 marked this pull request as ready for review January 13, 2025 10:21
@wpf500 wpf500 requested a review from JumpLink January 13, 2025 10:28
Copy link
Collaborator

@JumpLink JumpLink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! The code shows significant improvements in both functionality and structure 🚀

The code is ready to merge as is, but feel free to implement my suggestions before or after merge.


const source = map.value.getSource('responses') as GeoJSONSource;
source.getClusterExpansionZoom(cluster.properties.cluster_id, (err, zoom) => {
if (err || zoom == null) return;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe adding error logging here like this?

if (err || zoom == null) {
  console.error('Failed to get cluster expansion zoom:', err);
  return;
}

if (!map.value) return;

const feature = map.value.queryRenderedFeatures({
layers: ['unclustered-points', 'clusters'],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move magic strings to constants:

const LAYER_IDS = {
  CLUSTERS: 'clusters',
  UNCLUSTERED_POINTS: 'unclustered-points',
  SELECTED_RESPONSE: 'selected-response'
} as const;

.map(Number)
.sort();

return responses.value.filter((r) => responseNumbers.includes(r.number));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My coding assistant suggests a performance optimization here. Your current implementation has a complexity of O(n) lookup, but you can use Map for O(1) lookups:

const responseMap = new Map(responses.value.map(r => [r.number, r]));
const selectedResponses = responseNumbers.map(n => responseMap.get(n)).filter(Boolean);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants